/*
 * =====================================================================================
 *
 *       Filename:  main.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  02/07/2018 11:33:19 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef __MAIN_H__
#define __MAIN_H__
#include <ev.h>
#include "buffer.h"
#include "netutils.h"

struct conn;
typedef struct conn_ctx {
	ev_io io;
	ev_timer watcher;
	struct conn *conn;
} conn_ctx_t;

typedef struct conn {
	int fd;
	buffer_t *buf;
	ev_timer heartbeat;
	conn_ctx_t *recv_ctx;
	conn_ctx_t *send_ctx;
} conn_t;

typedef struct server_ctx {
	ev_io io;
	int connected;
	ev_timer watcher;
	struct server *server;
} server_ctx_t;

typedef struct remote_ctx {
	ev_io io;
	int connected;
	ev_timer watcher;
	struct remote *remote;
} remote_ctx_t;

typedef struct remote {
	int fd;
	buffer_t *buf;
	struct remote_ctx *recv_ctx;
	struct remote_ctx *send_ctx;
	struct server *server;
} remote_t;

typedef struct server {
	int fd;
	buffer_t *buf;
	struct server_ctx *recv_ctx;
	struct server_ctx *send_ctx;
	char   stage;

	remote_t *remote;
#ifdef CONNLOG
	dst_t dst;
#endif
	struct list_head entries;
} server_t;
#endif /* __MAIN_H__ */
